﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SeaBattle.Domain.Abstract.Services;
using SeaBattle.Domain.Entities;

namespace SeaBattle.Domain.Concrete.Services
{
    public class FakePlayerService: IPlayerService
    {
        private static List<Player> players = new List<Player>{
         new Player("Василий Пупкин","vasya"),
         new Player("Александр Македонский","alex"),
         new Player("Андрей Шевченко","andrew")                                              
        };

        public bool PlayerExists(string name)
        {
            return players.Exists(x => x.Name == name);
        }

        public void RegisterNewPlayer(Player player)
        {
            if(!PlayerExists(player.Name))
            {
                players.Add(player);
            }
        }


        public Player GetPlayer(string login)
        {
            var player = players.FirstOrDefault(x => x.Login == login);
            if(player == null)
            {
                throw new IndexOutOfRangeException("Player with login "+login+" doesnt exists");
            }
            return player;
        }
    }
}
